;
function getOption() {
    var id = $('#id').val();
    var opType = $('#opType').val();
    if (opType == 0) {
        $("#htmlTitle").html("新建文章");
        $(".save").css("display", "inline-block");
        $("#cancel").css("display", "inline-block");
    } else if (opType == 1) {
        $("#htmlTitle").html("编辑文章");
        $(".save").css("display", "inline-block");
        $("#cancel").css("display", "inline-block");
    } else if (opType == 2) {
        $("#htmlTitle").html("文章详情");
        $("#back").css("display", "inline-block");

    }
    if (opType == 2) {
        $("#back").click(function () {
            $.ajaxSetup({cache: false});
            $(".mainDiv").load('htmlWeb/systemArticleHtml', '', function () {
                $.getScript("../../by-webhtml/assets/js/system/system_article.js");
            });
        });
    } else {
        $(".save").click(function () {
            var options = {
                dataType: 'json',
                success: function (data) {
                    if (data.msg== 'success') {
                        if (data.r != null) alert("文章编辑成功");
                        else alert("文章新建成功");
                    } else {
                        if (data.r != null) alert("文章编辑失败");
                        else alert("文章新建失败");
                    }
                    $.ajaxSetup({cache: false});
                    $(".mainDiv").load('htmlWeb/systemArticleHtml', '', function () {
                        $.getScript("../../by-webhtml/assets/js/system/system_article.js");
                    });
                }
            };
            $("#articleForm").ajaxForm(options);
        });
        $("#cancel").click(function () {
            $.ajaxSetup({cache: false});
            $(".mainDiv").load('htmlWeb/systemArticleHtml', '', function () {
                $.getScript("../../by-webhtml/assets/js/system/system_article.js");
            });
        });
    }
    $.post("htmlWeb/article/getOption", {id: id}, function (data) {
        var _arType = "",_artPosition="";
        $.each(data.articleType, function (index, obj) {
            var opt = obj.split(";");
            _arType += '<option value="' + opt[0] + '">' + opt[1] + '</option>'
        });
        $.each(data.artPosition, function (index, obj) {
            var opt = obj.split(";");
            _artPosition += '<option value="' + opt[0] + '">' + opt[1] + '</option>'
        });
        $("#articleType").append(_arType);
        $("#positionId").append(_artPosition);
        if (id != '') {
            $("#articleForm").setValues(data.article);
        }
    });
}
$(function () {
    getOption();
});
